using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlTypes;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace FutureOpen.Core.func.sql
{
    public class ResumeProvider
    {

        public static readonly int RESUME_OPEN = 1;
        public static readonly int RESUME_FRD = 2;
        public static readonly int RESUME_CLOSE = 3;


        public static readonly string SQL_GET_PRESUME = "update presume set presume_view=presume_view+1 where presume_usr={0};select * from presume where presume_usr={0}";
        public static  DataRow GetPResume(int uid)
        {
            string sql = string.Format(SQL_GET_PRESUME, uid);
            return MySqlHelper.ExecuteDatarow(MySqlHelper.CONNSTR(), sql, null); 
        }

        public static readonly string SQL_GET_IPRESUME = "update iresume set iresume_view=iresume_view+1 where iresume_usr={0};select * from iresume where iresume_usr={0};";
        public static DataRow GetIResume(int uid)
        {
            string sql = string.Format(SQL_GET_IPRESUME, uid);
            return MySqlHelper.ExecuteDatarow(MySqlHelper.CONNSTR(), sql, null);
        }

        public static readonly string SQL_GET_PRESUME_ID = "select presume_id from presume where presume_usr={0}";
        public static readonly string SQL_ADD_PRESUME = "INSERT INTO Presume(presume_usr,presume_bio,presume_tech,presume_honor, presume_exp,"
            +" presume_study, presume_status) VALUES ({0},'{1}','{2}','{3}','{4}','{5}',{6});";
        public static readonly string SQL_UPDATE_PRESUME = "update presume set presume_bio='{0}',presume_tech='{1}',presume_honor='{2}', presume_exp='{3}',"
            + " presume_study = '{4}', presume_status = {5} where presume_id={6}";
        public static void UpdatePresume(int uid, string bio, string tech, string honor, string exp, string study, int status)
        {
            string sql = string.Format(SQL_GET_PRESUME_ID, uid);
            object obj = MySqlHelper.ExecuteScalar(MySqlHelper.CONNSTR(), sql);
            if (obj != null)
            {
                int id = Convert.ToInt32(obj);
                sql = string.Format(SQL_UPDATE_PRESUME, bio, tech, honor, exp, study, status, id);
                MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
            }
            else
            {
                sql = string.Format(SQL_ADD_PRESUME, uid, bio, tech, honor, exp, study, status);
                MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
            } 
        }

        
        public static readonly string SQL_GET_IRESUME_ID = "select iresume_id from iresume where iresume_usr={0}";
        public static readonly string SQL_ADD_IPRESUME = "INSERT INTO IResume(iresume_usr,iresume_content, iresume_status) VALUES ({0},'{1}',{2});";
        public static readonly string SQL_UPDATE_IRESUME = "update iresume set iresume_content='{0}',iresume_status{1} where iresume_id={2}";
        public static void UpdateIResume(int uid, string content, int status)
        {
            string sql = string.Format(SQL_GET_IRESUME_ID, uid);
            object obj = MySqlHelper.ExecuteScalar(MySqlHelper.CONNSTR(), sql);
            if (obj != null)
            {
                int id = Convert.ToInt32(obj);
                sql = string.Format(SQL_UPDATE_IRESUME, content, id);
                MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
            }
            else
            {
                sql = string.Format(SQL_ADD_IPRESUME, uid, content, status);
                MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
            }
        }      
    }
}
